import os.path, shutil

# based on code from ipython (kernel/util.py), BSD licence
def export_module(mod, outdir):
    """   
    Notes:

    - It will handle both single module files, as well as packages.
    - The byte code files (\*.pyc) are not deleted.
    - It has not been tested with modules containing extension code, but 
      it should work in most cases.
    - There are cross platform issues. 
     
    """
     
    module_dir, module_file = os.path.split(mod.__file__)

    if "__init__.py" in module_file:
        # module is a package
        shutil.copytree(module_dir, outdir)
    else:                          
        # simple module
        module_file = module_file.split('.')[0] + ".py"
        shutil.copy2(os.path.join(module_dir, module_file), outdir)

def export_path(path, outdir):
    if os.path.isfile(path):
        shutil.copy2(path, os.path.join(outdir, os.path.basename(path)))
    elif os.path.isdir(path):
        shutil.copytree(path, outdir)

